package ru.ifmo.cppsc.grammar;

public class CompoundProduction extends Production {
    public final int position;
    public final Production child;
    private final Production production;

     public CompoundProduction(Production production, int position, Production child) {
         super(production.getLeft(), production.getRight(), "");
         this.production = production;
         this.position = position;
         this.child = child;
    }

    public Symbol[] getRight() {

        Symbol[] r1 = super.getRight();
        Symbol[] r = child.getRight();
        Symbol[] res = new Symbol[r1.length - 1 + r.length];

        System.arraycopy(r1, 0, res, 0, position);
        System.arraycopy(r, 0, res, position, r.length);
        System.arraycopy(r1, position + 1, res, position + r.length, r1.length - position - 1);

        return res;
    }

    public boolean isCompoundProduction() {
        return true;
    }

    public Production get() {
        return production.get();
    }
}